#include<iostream>
#include<string>
using namespace std;

int main()
{
	int q;
	cin >> q;
	string str;
	cin >> str;
	int n;
	string s1;
	int a,b;
	
	while(q--)
	{
		cin >> n;
		switch(n)
		{
			case 1:
				cin >> s1;
				str += s1;
				cout << str << endl;
				break;
			case 2:
				cin >> a >> b;
				str = str.substr(a,b);
				cout << str << endl;
				break;
			case 3:
				cin >> a >> s1;
				str.insert(a,s1);
				cout << str << endl;
				break;
			case 4:
				cin >> s1;
				size_t m = str.find(s1);
				if(m == string::npos)
					cout << "-1" << endl;
				else
					cout << m << endl;
				break;
		}
	}
	return 0;
 } 
